package cn.edu.nuaa.aadl2.generatorC.workflow

import org.osate.aadl2.SystemImplementation
import cn.edu.nuaa.aadl2.generatorC.utils.Tools
import cn.edu.nuaa.aadl2.generatorC.template.Template
import static extension cn.edu.nuaa.aadl2.generatorC.template.Template.*
import static extension cn.edu.nuaa.aadl2.generatorC.template.SystemTemplate.*
import static extension cn.edu.nuaa.aadl2.generatorC.utils.StringUtils.*
import java.io.PrintStream
import org.eclipse.core.resources.IFolder
import org.eclipse.core.resources.IProject

class Generate {
	def static generate(SystemImplementation system,String parentFolder){
		if (system.name!==null){
			Tools.folder(parentFolder+"/"+system.name.convert)
			Template.packageName= Tools.getPackageName(system.eContainer.eContainer.toString)
			Template.subprogramsFileName = Template.packageName+"_Subprograms"
			generateSystem(parentFolder,system)
			Tools.ifolder=null
		}
	}
	
	/**
	 * 顶层系统生成,直接在插件响应处调用
	 * 额外进行了Template的初始化
	 */
	def static generate(SystemImplementation system,IProject iProject,String path,String platForm){
		Tools.redirectSystemOut
		if (system.name!==null){
			CFolder="C_codes"
			System.out.println("-----------meteSys start!------------")
			Template.initMap
			Tools.currentProject = iProject
			Tools.initfolder(CFolder)
			var f=Tools.folder(CFolder)
			//abolutePathOfSystem=f.fullPath.toString
			Template.aimPath=path
			Template.packageName=Tools.getPackageName(system.eContainer.eContainer.toString)
			Template.subprogramsFileName = Template.packageName+"_Subprograms"
			generateSystem(CFolder,system)
//			//test.createNullFiles(100);
			Tools.ifolder=null
			Tools.initProject
			Template.init
			
			System.out.println("-----------meteSys end!------------")
			
		}
	}

}